package com.qf.ssm.controller;

import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.entity.Store;
import com.qf.ssm.service.ClassifyAppService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 86155
 * @ClassName: com.qf.ssm.controller.ClassifyController
 * @Description: 该类的功能描述
 * @date: 2021/10/12 17:29
 */

@RestController
@RequestMapping("/classify")
public class ClassifyAppController {
    @Resource
    private ClassifyAppService classifyService;

    /**
     * 按销量排序
     *
     * @param sort
     * @return
     */
    @GetMapping("/sales")
    public ResponseResult<List<Store>> classifyStoreBySales(@RequestParam("sort") Long sort,
                                                            @RequestParam(defaultValue = "1") Integer page,
                                                            @RequestParam(defaultValue = "10") Integer size) {
        List<Store> stores = classifyService.classifyStoreBySales(sort, page, size);
        return ResponseResult.success(stores);
    }

    /**
     * 按评分排序
     *
     * @param score
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/score")
    public ResponseResult<List<Store>> classifyStoreByScore(@RequestParam("score") Long score,
                                                            @RequestParam(defaultValue = "1") Integer page,
                                                            @RequestParam(defaultValue = "10") Integer size) {
        List<Store> stores = classifyService.classifyStoreByScore(score, page, size);
        return ResponseResult.success(stores);
    }

    /**
     * 展示全部商店
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/find/all")
    public ResponseResult<List<Store>> findAllStore(@RequestParam(defaultValue = "1") Integer page,
                                                    @RequestParam(defaultValue = "10") Integer size) {
        List<Store> stores = classifyService.findAllStore(page, size);
        return ResponseResult.success(stores);
    }

}
